package sistemadeproyectos;

import javax.swing.DefaultListModel;
import java.awt.GraphicsEnvironment;
import java.awt.Font;
/**
 *
 * @author Angel David
 */
public class Fuente extends javax.swing.JDialog {

    DefaultListModel modelo1;
    DefaultListModel modelo2;
    DefaultListModel modelo3;
    public Font fuenteEntregada = null;
    
    /** Creates new form Fuente */
    public Fuente(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        modelo1 = new DefaultListModel();
        modelo2 = new DefaultListModel();
        modelo3 = new DefaultListModel();
        jlstTipoLetra.setModel(modelo1);
        jlstEstiloLetra.setModel(modelo2);
        jlstTamano.setModel(modelo3);
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        //Array que recoge los nombres de las fuentes de caracteres
        String[] fuentes = env.getAvailableFontFamilyNames();
        //Se agregan los nombres de las fuentes en la lista
        for(int i = 0; i < fuentes.length; i++){
            modelo1.addElement(fuentes[i] );
        }
        //Se agregan los estilos de fuente posibles
        modelo2.addElement("Simple");
        modelo2.addElement("Negrita");
        modelo2.addElement("Cursiva");
        modelo2.addElement("Negrita cursiva");
        //Se agregan los tamaños más usados
        modelo3.addElement("8");
        modelo3.addElement("9");
        modelo3.addElement("10");
        modelo3.addElement("11");
        modelo3.addElement("12");
        modelo3.addElement("14");
        modelo3.addElement("16");
        modelo3.addElement("18");
        modelo3.addElement("20");
        modelo3.addElement("22");
        modelo3.addElement("24");
        modelo3.addElement("26");
        modelo3.addElement("28");
        modelo3.addElement("36");
        
        jlstTipoLetra.setSelectedIndex(0);
        jlstEstiloLetra.setSelectedIndex(0);
        jlstTamano.setSelectedIndex(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlstTipoLetra = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlstEstiloLetra = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        jlstTamano = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();
        jlblTextoEjemplo = new javax.swing.JLabel();
        jbtnAceptar = new javax.swing.JButton();
        jbtnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemadeproyectos.SistemadeproyectosApp.class).getContext().getResourceMap(Fuente.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jlstTipoLetra.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jlstTipoLetra.setName("jlstTipoLetra"); // NOI18N
        jlstTipoLetra.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlstTipoLetraValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jlstTipoLetra);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jlstEstiloLetra.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jlstEstiloLetra.setName("jlstEstiloLetra"); // NOI18N
        jlstEstiloLetra.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlstEstiloLetraValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jlstEstiloLetra);

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jlstTamano.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jlstTamano.setName("jlstTamano"); // NOI18N
        jlstTamano.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlstTamanoValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(jlstTamano);

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jlblTextoEjemplo.setText(resourceMap.getString("jlblTextoEjemplo.text")); // NOI18N
        jlblTextoEjemplo.setName("jlblTextoEjemplo"); // NOI18N

        jbtnAceptar.setText(resourceMap.getString("jbtnAceptar.text")); // NOI18N
        jbtnAceptar.setName("jbtnAceptar"); // NOI18N
        jbtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAceptarActionPerformed(evt);
            }
        });

        jbtnCancelar.setText(resourceMap.getString("jbtnCancelar.text")); // NOI18N
        jbtnCancelar.setName("jbtnCancelar"); // NOI18N
        jbtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(55, 55, 55)
                        .addComponent(jlblTextoEjemplo, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
                        .addGap(97, 97, 97))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(jbtnCancelar, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(23, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGap(82, 82, 82)
                .addComponent(jbtnAceptar)
                .addContainerGap(276, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jlblTextoEjemplo, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtnAceptar)
                    .addComponent(jbtnCancelar))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jlstTipoLetraValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlstTipoLetraValueChanged
        // TODO add your handling code here:
        cambiarFuente();
    }//GEN-LAST:event_jlstTipoLetraValueChanged

    private void jlstEstiloLetraValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlstEstiloLetraValueChanged
        // TODO add your handling code here:
        cambiarFuente();
    }//GEN-LAST:event_jlstEstiloLetraValueChanged

    private void jlstTamanoValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlstTamanoValueChanged
        // TODO add your handling code here:
        cambiarFuente();
    }//GEN-LAST:event_jlstTamanoValueChanged

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        // TODO add your handling code here:
        this.fuenteEntregada = jlblTextoEjemplo.getFont();
        this.dispose();
    }//GEN-LAST:event_jbtnAceptarActionPerformed

    private void jbtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jbtnCancelarActionPerformed

    private void cambiarFuente(){
        if (jlstTipoLetra.getSelectedIndex() >= 0 && jlstEstiloLetra.getSelectedIndex() >= 0 && jlstTamano.getSelectedIndex() >= 0){
            int indiceLetra = jlstTipoLetra.getSelectedIndex();
            int indiceEstilo = jlstEstiloLetra.getSelectedIndex();
            int indiceTamano = jlstTamano.getSelectedIndex();
            String nombreFuente = (String)modelo1.elementAt(indiceLetra);
            int tamanoFuente = Integer.parseInt((String)modelo3.elementAt(indiceTamano));
            jlblTextoEjemplo.setText(nombreFuente);
            Font laFuente = null;
            if(indiceEstilo == 0){
                laFuente = new Font(nombreFuente,Font.PLAIN,tamanoFuente);
            }
            else if(indiceEstilo == 1){
                laFuente = new Font(nombreFuente,Font.BOLD,tamanoFuente);
            }
            else if(indiceEstilo == 2){
                laFuente = new Font(nombreFuente,Font.ITALIC,tamanoFuente);
            }
            else if(indiceEstilo == 3){
                laFuente = new Font(nombreFuente,Font.BOLD+Font.ITALIC,tamanoFuente);
            }            
            jlblTextoEjemplo.setFont(laFuente);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Fuente dialog = new Fuente(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JLabel jlblTextoEjemplo;
    private javax.swing.JList jlstEstiloLetra;
    private javax.swing.JList jlstTamano;
    private javax.swing.JList jlstTipoLetra;
    // End of variables declaration//GEN-END:variables
}
